home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 05 inheritance / inheritancedemo / classes.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  21.8 KB  |  776 lines

  1. ' The first version of the Person class demonstrates properties, methods, indexers,
  2. ' read-only, write-only, and default properties
  3.  
  4. Class Person
  5.     ' Visual Basic.NET classes can expose Public constants.
  6.     Public Const DefaultPassword As String = "mypwd"
  7.  
  8.     ' Fields visible from outside the class
  9.     Public FirstName As String
  10.     Public LastName As String
  11.  
  12.     ' You can define up to four addresses for this person,
  13.     ' from Address(0) to Address(3).
  14.     Public Address(3) As String
  15.  
  16.     ' an overridable method
  17.  
  18.     Overridable Function CompleteName(Optional ByVal title As String = "") As String
  19.         ' Use the title, if provided.
  20.         If title <> "" Then CompleteName = title & " "
  21.         ' Append first and last name.
  22.         CompleteName &= FirstName & " " & LastName
  23.     End Function
  24.  
  25.     ' the BirthDate property
  26.  
  27.     Dim m_BirthDate As Date
  28.  
  29.     Property BirthDate() As Date
  30.         Get
  31.             Return m_BirthDate
  32.         End Get
  33.         Set(ByVal Value As Date)
  34.             m_BirthDate = Value
  35.         End Set
  36.     End Property
  37.  
  38.     ' the Spouse property
  39.  
  40.     Private m_Spouse As Person
  41.  
  42.     Property Spouse() As Person
  43.         Get
  44.             Return m_Spouse
  45.         End Get
  46.         Set(ByVal Value As Person)
  47.             m_Spouse = Value
  48.         End Set
  49.     End Property
  50.  
  51.     ' The Age property is read-only.
  52.  
  53.     ReadOnly Property Age() As Integer
  54.         Get
  55.             Return Year(Now) - Year(m_BirthDate)
  56.         End Get
  57.     End Property
  58.  
  59.     ' LoginDate is a write-only property.
  60.  
  61.     Dim m_LoginDate As Date
  62.  
  63.     WriteOnly Property LoginDate() As Date
  64.         Set(ByVal Value As Date)
  65.             m_LoginDate = Value
  66.         End Set
  67.     End Property
  68.  
  69.     ' an example of indexer
  70.  
  71.     Dim m_Notes(10) As String
  72.  
  73.     ' The Attachment property takes an Integer argument.
  74.     ' Note that this is also the default property.
  75.  
  76.     Default Property Notes(ByVal index As Integer) As String
  77.         Get
  78.             If index < 0 Or index > UBound(m_Notes) Then
  79.                 Throw New IndexOutOfRangeException("Invalid note index")
  80.             End If
  81.             Return m_Notes(index)
  82.         End Get
  83.         Set(ByVal Value As String)
  84.             If index < 0 Or index > UBound(m_Notes) Then
  85.                 Throw New IndexOutOfRangeException("Invalid note index")
  86.             End If
  87.             m_Notes(index) = Value
  88.         End Set
  89.     End Property
  90.  
  91.     ' The GotMail event is used to demonstrate event inheritance
  92.  
  93.     Event GotMail(ByVal msgText As String)
  94.  
  95.     Sub NotifyNewMail(ByVal msgText As String)
  96.         ' Let all listeners know that we got mail.
  97.         RaiseEvent GotMail(msgText)
  98.     End Sub
  99.  
  100.     ' The Father, Mother and AreBrothers method are used to demonstrate shared member inheritance
  101.  
  102.     Public Father As Person
  103.     Public Mother As Person
  104.  
  105.     Shared Function AreBrothers(ByVal p1 As Person, ByVal p2 As Person) As Boolean
  106.         Return (p1.Father Is p2.Father) Or (p1.Mother Is p2.Mother)
  107.     End Function
  108. End Class
  109.  
  110. ' This second version of the Person class demonstrates overloaded constructors, 
  111. ' read-only fields, and the Finalize method.
  112.  
  113. Class Person2
  114.     ' a public read-only field that can be assigned only from inside the constructor.
  115.     Public ReadOnly CreateTime As Date
  116.  
  117.     ' First version takes first and last name.
  118.     Sub New(ByVal firstName As String, ByVal lastName As String)
  119.         Me.FirstName = firstName
  120.         Me.LastName = lastName
  121.         ' Remember when this instance was created.
  122.         CreateTime = Now()
  123.     End Sub
  124.  
  125.     ' Second version takes complete name (e.g. "Joe Doe").
  126.     Sub New(ByVal completeName As String)
  127.         Dim i As Integer
  128.         i = InStr(completeName, " ")
  129.         ' Error if there are fewer than two words.
  130.         If i = 0 Then Throw New ArgumentException("Invalid Name")
  131.         ' Initialize main properties.
  132.         Me.FirstName = RTrim(Left(completeName, i - 1))
  133.         Me.LastName = LTrim(Mid(completeName, i + 1))
  134.         ' Remember when this instance was created.
  135.         CreateTime = Now()
  136.     End Sub
  137.  
  138.  
  139.     Private m_FirstName As String
  140.     Private m_LastName As String
  141.  
  142.     Property FirstName() As String
  143.         Get
  144.             Return m_FirstName
  145.         End Get
  146.         Set(ByVal Value As String)
  147.             If Value = "" Then
  148.                 Throw New ArgumentException("Invalid FirstName property")
  149.             End If
  150.             m_FirstName = Value
  151.         End Set
  152.     End Property
  153.  
  154.     Property LastName() As String
  155.         Get
  156.             Return m_LastName
  157.         End Get
  158.         Set(ByVal Value As String)
  159.             If Value = "" Then
  160.                 Throw New ArgumentException("Invalid LastName property")
  161.             End If
  162.             m_LastName = Value
  163.         End Set
  164.     End Property
  165.  
  166.     ' the BirthDate property
  167.  
  168.     Dim m_BirthDate As Date
  169.  
  170.     Property BirthDate() As Date
  171.         Get
  172.             Return m_BirthDate
  173.         End Get
  174.         Set(ByVal Value As Date)
  175.             m_BirthDate = Value
  176.         End Set
  177.     End Property
  178.  
  179.     Overridable Function CompleteName() As String
  180.         ' Append first and last name.
  181.         Return FirstName & " " & LastName
  182.     End Function
  183.  
  184.     Protected Overrides Sub Finalize()
  185.         ' NOTE: we output this message to the debug window (instead of the console)
  186.         ' because if the Finalize method is called by the very last GC that fires
  187.         ' when the application completes, then the Console object isn't available any longer.
  188.         Debug.WriteLine("Person " & Me.CompleteName() & " is being destroyed")
  189.     End Sub
  190.  
  191. End Class
  192.  
  193.  
  194. ' The Person3 class demonstrates how to use the MyClass keyword and the problems 
  195. ' you have when you omit it
  196.  
  197. Enum Gender
  198.     NotSpecified
  199.     Male
  200.     Female
  201. End Enum
  202.  
  203. Class Person3
  204.     ' (In a real-world class, these would be properties.)
  205.     Public FirstName As String
  206.     Public LastName As String
  207.     Public Gender As Gender = Gender.NotSpecified
  208.  
  209.     ' the usual constructor
  210.     Sub New(ByVal firstName As String, ByVal lastName As String)
  211.         Me.FirstName = firstName
  212.         Me.LastName = lastName
  213.     End Sub
  214.  
  215.  
  216.     Dim m_Title As String
  217.     Overridable Property Title() As String
  218.         Get
  219.             Return m_Title
  220.         End Get
  221.         Set(ByVal Value As String)
  222.             m_Title = Value
  223.         End Set
  224.     End Property
  225.  
  226.     ' Prefix the name with a title if one has been specified.
  227.     Function TitledName() As String
  228.         If Title <> "" Then
  229.             Return Title & " " & FirstName & " " & LastName
  230.         Else
  231.             Return FirstName & " " & LastName
  232.         End If
  233.     End Function
  234.  
  235.     Public BirthDate As Date
  236.  
  237.     ' Age is defined as the number of whole years passed from BirthDate.
  238.     Overridable ReadOnly Property Age() As Integer
  239.         Get
  240.             Age = CInt(DateDiff(DateInterval.Year, BirthDate, Now()))
  241.             If Month(Now) < Month(BirthDate) Or _
  242.                 (Month(Now) = Month(BirthDate) And _
  243.                 Day(Now) < Day(BirthDate)) Then
  244.                 ' Correct if this year's birthday hasn't occurred yet.
  245.                 Age = Age - 1
  246.             End If
  247.         End Get
  248.     End Property
  249.  
  250.     ' an incorrect version of the CanVote property
  251.     ReadOnly Property CanVote() As Boolean
  252.         Get
  253.             ' This statement isn't correct.
  254.             Return (Age >= 18)
  255.         End Get
  256.     End Property
  257.  
  258.     ' the correct version of the CanVote property
  259.     ReadOnly Property CanVote2() As Boolean
  260.         Get
  261.             ' Ensure that it always uses the non-overridden
  262.             ' version of the Age property.
  263.             Return (MyClass.Age >= 18)
  264.         End Get
  265.     End Property
  266.  
  267.     ' an non-overridable Address property
  268.     Dim m_Address As String
  269.  
  270.     Property Address() As String
  271.         Get
  272.             Return m_Address
  273.         End Get
  274.         Set(ByVal Value As String)
  275.             m_Address = Value
  276.         End Set
  277.     End Property
  278.  
  279. End Class
  280.  
  281.  
  282. ' The Widget class demonstrates the IDisposable interface.
  283. ' and performance of Overridable and NotOverridable methods.
  284.  
  285. Class Widget
  286.     Implements IDisposable
  287.  
  288.     Function GetInteger() As Integer
  289.         Return 1
  290.     End Function
  291.  
  292.     Overridable Function GetInteger2() As Integer
  293.         Return 1
  294.     End Function
  295.  
  296.     Sub Dispose() Implements IDisposable.Dispose
  297.         ' Close files and release other resources here.
  298.         ' ...
  299.     End Sub
  300. End Class
  301.  
  302.  
  303. ' This version of the DataFile class uses the GC.SuppressFinalize method
  304. ' for optimized clean-up code.
  305.  
  306. Class DataFile2
  307.     Implements IDisposable
  308.  
  309.     ' The file handle
  310.     Private handle As Integer
  311.  
  312.     ' Open a file, store its handle.
  313.     Sub Open(ByVal inputFile As String)
  314.         ' Throw an exception if the object has been already disposed.
  315.         If disposed Then Throw New ObjectDisposedException("DataFile2")
  316.         ' Continue with regular operations.
  317.         handle = FreeFile()
  318.         FileOpen(handle, inputFile, OpenMode.Input)
  319.     End Sub
  320.  
  321.     ' Close the file, don't throw an exception if already closed. 
  322.     Sub Close()
  323.         ' Throw an exception if the object has been already disposed.
  324.         If disposed Then Throw New ObjectDisposedException("DataFile2")
  325.         ' Continue with regular operations.
  326.         If handle <> 0 Then
  327.             FileClose(handle)
  328.             handle = 0
  329.         End If
  330.     End Sub
  331.  
  332.     ' This private variable is True if the object has been disposed.
  333.     Protected disposed As Boolean
  334.  
  335.     Sub Dispose() Implements IDisposable.Dispose
  336.         Debug.WriteLine("Dispose method")
  337.         ' Execute the code that does the clean up.
  338.         Dispose(True)
  339.         ' Let the CLR know that Finalize doesn't have to be called.
  340.         GC.SuppressFinalize(Me)
  341.     End Sub
  342.  
  343.     Protected Overrides Sub Finalize()
  344.         Debug.WriteLine("Finalize method")
  345.         ' Execute the code that does the clean up.
  346.         Dispose(False)
  347.     End Sub
  348.  
  349.     ' This procedure is where the actual cleanup occurs.
  350.     Protected Overridable Sub Dispose(ByVal disposing As Boolean)
  351.         ' Exit now if the object has been already disposed.
  352.         If disposed Then Exit Sub
  353.  
  354.         If disposing Then
  355.             ' The object is being disposed, not finalized. 
  356.             ' It is safe to access other objects (other than the base
  357.             ' object) only from inside this block.
  358.         End If
  359.  
  360.         ' Perform clean up chores that have to be executed in either case.
  361.         Close()
  362.  
  363.         ' Remember that the object has been disposed.
  364.         disposed = True
  365.     End Sub
  366. End Class
  367.  
  368. ' This class inherits from DataFile2 and overrides the Dispose and FInalize methods.
  369.  
  370. Class BetterDataFile2
  371.     Inherits DataFile2
  372.  
  373.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  374.         ' Exit now if the object has been already disposed.
  375.         If disposed Then Exit Sub
  376.  
  377.         If disposing Then
  378.             ' The object is being disposed, not finalized. 
  379.             ' It is safe to access other objects (other than the base
  380.             ' object) only from inside this block.
  381.         End If
  382.  
  383.         ' Perform clean up chores that have to be executed in either case.
  384.         ' ...
  385.  
  386.         ' Call the base class's Dispose method
  387.         MyBase.Dispose(disposing)
  388.     End Sub
  389.  
  390. End Class
  391.  
  392. ' The Employee class demonstrate inheritance
  393.  
  394. Class Employee
  395.     Inherits Person
  396.  
  397.     ' Two new public fields
  398.     Public BaseSalary As Single
  399.     Public HoursWorked As Integer
  400.     ' A new private field
  401.     Private m_HourlySalary As Single
  402.  
  403.     ' A new property
  404.     Property HourlySalary() As Single
  405.         Get
  406.             Return m_HourlySalary
  407.         End Get
  408.         Set(ByVal Value As Single)
  409.             m_HourlySalary = Value
  410.         End Set
  411.     End Property
  412.  
  413.     ' A new method
  414.     Function Salary() As Single
  415.         Return BaseSalary + m_HourlySalary * HoursWorked
  416.     End Function
  417.  
  418.     ' redefine the AreBrothers shared method
  419.  
  420.     Shared Shadows Function AreBrothers(ByVal e1 As Employee, _
  421.         ByVal e2 As Employee) As Boolean
  422.         Return Person.AreBrothers(e1, e2) And (e1.LastName = e2.LastName)
  423.     End Function
  424.  
  425. End Class
  426.  
  427. ' The second version of the Employee class demonstrates constructors with arguments
  428.  
  429. Class Employee2
  430.     Inherits Person2
  431.  
  432.     Public Title As String                 ' A new field
  433.  
  434.     ' two overloaded constructors 
  435.  
  436.     Sub New(ByVal firstName As String, ByVal lastName As String)
  437.         ' The first executable statement *must* be a call
  438.         ' to the constructor in the base class.
  439.         MyBase.New(firstName, lastName)
  440.         ' You can continue with the initialization step here.
  441.         ' ...
  442.     End Sub
  443.  
  444.     Sub New(ByVal firstName As String, ByVal lastName As String, ByVal title As String)
  445.         ' The first executable statement *must* be a call
  446.         ' to the constructor in the base class.
  447.         MyBase.New(firstName, lastName)
  448.         ' set the new field
  449.         Me.Title = title
  450.     End Sub
  451.  
  452.     Overrides Function CompleteName() As String
  453.         If Title <> "" Then CompleteName = Title & " "
  454.         CompleteName &= MyBase.CompleteName()
  455.     End Function
  456. End Class
  457.  
  458. Class Employee3
  459.     Inherits Person3
  460.  
  461.     ' the usual constructor
  462.     Sub New(ByVal firstName As String, ByVal lastName As String)
  463.         MyBase.New(firstName, lastName)
  464.     End Sub
  465.  
  466.     ' Always provide a title if one hasn't been assigned.
  467.     Overrides Property Title() As String
  468.         Get
  469.             If MyBase.Title <> "" Then
  470.                 Return MyBase.Title
  471.             ElseIf Gender = Gender.Male Then
  472.                 Return "Mr."
  473.             ElseIf Gender = Gender.Female Then
  474.                 Return "Mrs."
  475.             End If
  476.         End Get
  477.         Set(ByVal Value As String)
  478.             MyBase.Title = Value
  479.         End Set
  480.     End Property
  481.  
  482.     ' Age is defined as difference between the current year
  483.     ' and the year when the employee was born.
  484.     Overrides ReadOnly Property Age() As Integer
  485.         Get
  486.             Age = CInt(DateDiff(DateInterval.Year, BirthDate, Now()))
  487.         End Get
  488.     End Property
  489.  
  490.     ' the Address property demonstrates that you can always "manually" override
  491.     ' a procedure that is marked as non-overridable in the base class.
  492.     Shadows Property Address() As String
  493.         Get
  494.             Return MyBase.Address
  495.         End Get
  496.         Set(ByVal Value As String)
  497.             If Value = "" Then Throw New ArgumentException()
  498.             MyBase.Address = Value
  499.         End Set
  500.     End Property
  501.  
  502. End Class
  503.  
  504. ' Shape virtual class defines a behavior for other classes
  505.  
  506. MustInherit Class Shape
  507.     ' Position on the X-Y plane
  508.     Public X, Y As Single
  509.  
  510.     ' Move the object on the X-Y plane.
  511.     Sub Offset(ByVal deltaX As Single, ByVal deltaY As Single)
  512.         X = X + deltaX
  513.         Y = Y + deltaY
  514.         ' Redraw the shape at the new position.
  515.         Display()
  516.     End Sub
  517.  
  518.     ' A virtual method
  519.     MustOverride Sub Display()
  520. End Class
  521.  
  522. ' The Square class derives from Shape and also demonstrates how you can use
  523. ' private constructors
  524.  
  525. Class Square
  526.     Inherits Shape
  527.  
  528.     Public Side As Single
  529.  
  530.     Overrides Sub Display()
  531.         ' add here the statements that draw a square
  532.     End Sub
  533.  
  534.     ' This private constructor prevents clients from 
  535.     ' instancing this class directly.
  536.     Private Sub New(ByVal side As Single)
  537.         Me.Side = side
  538.     End Sub
  539.  
  540.     ' Clients can create a square only through this shared method.
  541.     Shared Function CreateSquare(ByVal side As Single) As Square
  542.         Return New Square(side)
  543.     End Function
  544.  
  545. End Class
  546.  
  547. ' The Animal and Peripheral classes demonstrate nested classes
  548.  
  549. Class Animal
  550.     ' ...
  551.     ' This class can be referred to as Animal.Mouse.
  552.     Class Mouse
  553.         ' ...
  554.     End Class
  555. End Class
  556.  
  557. Class Peripheral
  558.     Dim m As Mouse
  559.     Dim kb As Keyboard
  560.     Dim k As Keyboard.Key
  561.  
  562.     ' ...
  563.     ' This class can be referred to as Peripheral.Mouse.
  564.     Class Mouse
  565.         Dim kb As Keyboard
  566.         Dim k As Keyboard.Key
  567.         ' ...
  568.     End Class
  569.  
  570.     ' This class can be referred to as Peripheral.Keyboard.
  571.     Class Keyboard
  572.  
  573.         ' A private member
  574.         Dim m_Brand As String
  575.  
  576.         ' This shared member is True if this class supports
  577.         ' non-Latin keyboards.
  578.         Public Shared SupportsNonLatinKeyboards As Boolean
  579.  
  580.         ReadOnly Property Brand() As String
  581.             Get
  582.                 ' Code inside the outer class can access a private 
  583.                 ' member without any reference (Me is implicit). 
  584.                 Return m_Brand
  585.             End Get
  586.         End Property
  587.  
  588.         ' This class can be referred to as Peripheral.Keyboard.Key.
  589.         Class Key
  590.  
  591.             ' This public field is meant to be assigned when creating
  592.             ' an instance of the Key class.
  593.             Public ParentKeyboard As Keyboard
  594.  
  595.             ReadOnly Property Brand() As String
  596.                 Get
  597.                     ' Code inside the inner class can access a private member
  598.                     ' in the outer class, but requires an object reference.
  599.                     Return ParentKeyboard.m_Brand
  600.                 End Get
  601.             End Property
  602.  
  603.             ReadOnly Property SupportsNonLatin() As Boolean
  604.                 Get
  605.                     ' You can access a shared member in the outer class
  606.                     ' without an object reference.
  607.                     Return SupportsNonLatinKeyboards
  608.                 End Get
  609.             End Property
  610.  
  611.         End Class
  612.     End Class
  613. End Class
  614.  
  615. ' The Customer, GoodCustomer, and ForeignCustomer classes demonstrate scope concepts
  616.  
  617. Class Customer
  618.     ' This member is visible to this class and 
  619.     ' classes derived from this class.
  620.     Protected AlwaysPaysOnTime As Boolean
  621.  
  622.     ' Compute the discount percentage on products.
  623.     Protected Overridable Function ProductDiscount() As Single
  624.         ' Offer an additional discount if the customer always pays on time.
  625.         If AlwaysPaysOnTime Then
  626.             ProductDiscount = 15
  627.         Else
  628.             ProductDiscount = 10
  629.         End If
  630.     End Function
  631.  
  632.     ' By default make no discount on shipment.
  633.     Protected Overridable Function ShipmentDiscount() As Single
  634.         Return 0
  635.     End Function
  636.  
  637.     ' Compute the actual discount on an order, given the
  638.     ' amount of products purchased and the amount of shipment.
  639.     Function TotalOrderAmount(ByVal ProductAmount As Single, _
  640.         ByVal ShipmentAmount As Single) As Single
  641.         Return ProductAmount * (1 - ProductDiscount() / 100) _
  642.             + ShipmentAmount * (1 - ShipmentDiscount() / 100)
  643.     End Function
  644.  
  645.     ' a protected nested class
  646.     Protected Class OrderHistory
  647.         Public Count As Integer
  648.         Public TotalAmount As Single
  649.         ' ...
  650.     End Class
  651.  
  652. End Class
  653.  
  654. Class GoodCustomer
  655.     Inherits Customer
  656.  
  657.     Sub New()
  658.         ' Note that no MyBase.New is needed, because the base
  659.         ' class has no constructor with parameters.
  660.         AlwaysPaysOnTime = True
  661.     End Sub
  662.  
  663.     ' A derived class sees protected nested classes.
  664.     Dim oh As Customer.OrderHistory
  665.     ' Note that you don't even need the dot syntax.
  666.     Dim oh2 As OrderHistory
  667.  
  668. End Class
  669.  
  670. Class ForeignCustomer
  671.     Inherits Customer
  672.  
  673.     ' A convenient constructor that lets us test well- and 
  674.     ' ill-behaved foreign customers.
  675.     Sub New(ByVal alwaysPaysOnTime As Boolean)
  676.         Me.AlwaysPaysOnTime = alwaysPaysOnTime
  677.     End Sub
  678.  
  679.     ' We don't charge shipment to well-behaved foreign customers.
  680.     Protected Overrides Function ShipmentDiscount() As Single
  681.         If AlwaysPaysOnTime Then ShipmentDiscount = 100
  682.     End Function
  683. End Class
  684.  
  685. ' the DataReader and FileDateReader classes demonstrate the simplest technique
  686. ' for a derived class to trap events from a base class
  687.  
  688. Class DataReader
  689.     Event DataAvailable()
  690.  
  691.     Sub GetNewData()
  692.         RaiseEvent DataAvailable()
  693.     End Sub
  694. End Class
  695.  
  696. Class FileDataReader
  697.     Inherits DataReader
  698.  
  699.     ' This variable will point to the object itself (Me).
  700.     Dim WithEvents EventSink As FileDataReader
  701.     ' This counter must be incremented after each event.
  702.     Public EventCounter As Integer
  703.  
  704.     Sub New()
  705.         MyBase.New()
  706.         EventSink = Me
  707.     End Sub
  708.  
  709.     Private Sub NotifyDataAvailable() Handles EventSink.DataAvailable
  710.         ' Increment the counter.
  711.         EventCounter += 1
  712.     End Sub
  713. End Class
  714.  
  715. ' The DataReader2 and FileDataReader2 classes demonstrate a more sophisticated technique
  716. ' for a derived class to control events fired in its base class
  717.  
  718. Class DataReader2
  719.     Event DataAvailable()
  720.  
  721.     Sub GetNewData()
  722.         OnDataAvailable()
  723.     End Sub
  724.  
  725.     Protected Overridable Sub OnDataAvailable()
  726.         RaiseEvent DataAvailable()
  727.     End Sub
  728. End Class
  729.  
  730. Class FileDataReader2
  731.     Inherits DataReader2
  732.  
  733.     ' This counter must be incremented after each event.
  734.     Public EventCounter As Integer
  735.  
  736.     Protected Overrides Sub OnDataAvailable()
  737.         ' Increment the counter.
  738.         EventCounter += 1
  739.         ' Raise only up to 10 events.
  740.         If EventCounter <= 10 Then MyBase.OnDataAvailable()
  741.     End Sub
  742. End Class
  743.  
  744. ' these classes are used to test member shadowing
  745.  
  746. Class AAA
  747.     Sub DoSomething()
  748.         Console.WriteLine("AAA.DoSomething")
  749.     End Sub
  750.     Sub DoSomething(ByVal msg As String)
  751.         Console.WriteLine("AAA.DoSomething({0})", msg)
  752.     End Sub
  753.  
  754.     Sub DoSomething2()
  755.         Console.WriteLine("AAA.DoSomething2")
  756.     End Sub
  757.     Sub DoSomething2(ByVal msg As String)
  758.         Console.WriteLine("AAA.DoSomething2({0})", msg)
  759.     End Sub
  760.  
  761. End Class
  762.  
  763. Class BBB
  764.     Inherits AAA
  765.  
  766.     Overloads Sub DoSomething()
  767.         Console.WriteLine("BBB.DoSomething")
  768.     End Sub
  769.  
  770.     Private Shadows Sub DoSomething2()
  771.         Console.WriteLine("BBB.DoSomething2")
  772.     End Sub
  773.  
  774. End Class
  775.  
  776.